package com.opdar.athena.web.controllers;

import com.opdar.athena.entities.UserEntity;
import com.opdar.athena.web.interceptors.AuthViewInterceptor;
import com.opdar.athena.web.service.UserService;
import com.opdar.platform.annotations.Interceptor;
import com.opdar.platform.annotations.Request;
import com.opdar.platform.core.base.Context;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.UUID;

/**
 * Created by shiju on 2017/6/20.
 */
@Controller
@Interceptor(AuthViewInterceptor.class)
public class UserController {
    @Autowired
    UserService userService;

    @Request(value = "/user/update", format = Request.Format.VIEW)
    public Object edit(UserEntity update) {
        UserEntity where = new UserEntity();
        where.setId(update.getId());
        boolean ret = userService.update(update,where);
        String referer = Context.getRequest().getHeader("referer");
        return "redirect:"+referer;
    }
    @Request(value = "/user/insert", format = Request.Format.VIEW)
    public Object insert(UserEntity insert) {
        boolean ret = userService.insert(insert);
        String referer = Context.getRequest().getHeader("referer");
        return "redirect:"+referer;
    }
}
